using ASP;
using HoWave.Web;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.WebControls;
public class UserControls_productGV : UserControl
{
	protected string _productIDS = string.Empty;
	protected string _productNums = string.Empty;
	protected string _productPrices = string.Empty;
	private Shop_Product _product = null;
	protected GridView GridView1;
	protected HiddenField hd_productIDS;
	protected HiddenField hd_productNum;
	protected HiddenField hd_productPrice;
	public string productIDS
	{
		get
		{
			return this._productIDS;
		}
		set
		{
			this._productIDS = value;
		}
	}
	public string productNums
	{
		get
		{
			return this._productNums;
		}
		set
		{
			this._productNums = value;
		}
	}
	public string productPrices
	{
		get
		{
			return this._productPrices;
		}
		set
		{
			this._productPrices = value;
		}
	}
	protected Shop_Product product
	{
		get
		{
			Shop_Product product;
			if (this._product == null)
			{
				this._product = new Shop_Product();
				product = this._product;
			}
			else
			{
				product = this._product;
			}
			return product;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.hd_productIDS.Value = this.productIDS.Substring(0, this.productIDS.Length - 1);
			this.hd_productNum.Value = this.productNums.Substring(0, this.productNums.Length - 1);
			this.hd_productPrice.Value = this.productPrices.Substring(0, this.productPrices.Length - 1);
			this.loadinfo();
			this.RepartPrice();
		}
	}
	public void RepartPrice()
	{
		Shop_Product shop_Product = new Shop_Product();
		for (int i = 0; i < this.GridView1.Rows.Count; i++)
		{
			int partID = int.Parse(((HiddenField)this.GridView1.Rows[i].FindControl("HiddenID")).Value);
			if (shop_Product.IfJustPart(partID))
			{
				DataTable partProduct = shop_Product.GetPartProduct(partID);
				if (partProduct != null)
				{
					this.GridView1.Rows[i].Cells[4].Text = partProduct.Rows[0]["yikouPrice"].ToString();
				}
			}
			decimal d = decimal.Parse(this.GridView1.Rows[i].Cells[4].Text);
			int value = int.Parse(this.GridView1.Rows[i].Cells[5].Text);
			this.GridView1.Rows[i].Cells[6].Text = (d * value).ToString();
		}
	}
	public string StrSizeColor(string StrSizeCol)
	{
		string result;
		if (StrSizeCol == "")
		{
			result = "默认";
		}
		else
		{
			result = StrSizeCol;
		}
		return result;
	}
	public string StrAttributes(object obj)
	{
		string result;
		if (!string.IsNullOrEmpty(obj.ToString()))
		{
			result = obj.ToString();
		}
		else
		{
			result = "无";
		}
		return result;
	}
	private DataTable getProducts()
	{
		string productIDS = this.productIDS.Substring(0, this.productIDS.Length - 1);
		return this.product.getProductadnshopByProductIDS(productIDS);
	}
	private DataTable setNewDataTable()
	{
		DataTable dataTable = new DataTable();
		DataColumn column = new DataColumn("productID", typeof(int));
		dataTable.Columns.Add(column);
		DataColumn column2 = new DataColumn("productName", typeof(string));
		dataTable.Columns.Add(column2);
		DataColumn column3 = new DataColumn("productNum", typeof(int));
		dataTable.Columns.Add(column3);
		DataColumn column4 = new DataColumn("shopName", typeof(string));
		dataTable.Columns.Add(column4);
		DataColumn column5 = new DataColumn("shopID", typeof(int));
		dataTable.Columns.Add(column5);
		DataColumn column6 = new DataColumn("total", typeof(int));
		dataTable.Columns.Add(column6);
		DataColumn column7 = new DataColumn("standPrice", typeof(decimal));
		dataTable.Columns.Add(column7);
		DataColumn column8 = new DataColumn("ShoppingCarGuige", typeof(string));
		dataTable.Columns.Add(column8);
		DataColumn column9 = new DataColumn("SizeAttribute", typeof(string));
		dataTable.Columns.Add(column9);
		string[] array = this.productIDS.Substring(0, this.productIDS.Length - 1).Split(new char[]
		{
			','
		});
		string[] array2 = this.productNums.Substring(0, this.productNums.Length - 1).Split(new char[]
		{
			','
		});
		string[] array3 = this.productPrices.Substring(0, this.productPrices.Length - 1).Split(new char[]
		{
			','
		});
		DataTable products = this.getProducts();
		foreach (DataRow dataRow in products.Rows)
		{
			DataRow dataRow2 = dataTable.NewRow();
			dataRow2["productName"] = dataRow["ProductName"].ToString();
			dataRow2["shopName"] = dataRow["shopName"].ToString();
			dataRow2["shopID"] = int.Parse(dataRow["shopID"].ToString());
			dataRow2["productID"] = int.Parse(dataRow["productID"].ToString());
			dataRow2["ShoppingCarGuige"] = dataRow["ShoppingCarGuige"].ToString();
			dataRow2["SizeAttribute"] = dataRow["SizeAttribute"].ToString();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i] == dataRow["productID"].ToString())
				{
					dataRow2["productNum"] = int.Parse(array2[i]);
					if (array3[i] != "" || array3[i] != "0")
					{
						dataRow2["standPrice"] = array3[i];
						dataRow2["total"] = int.Parse(array2[i]) * decimal.Parse(array3[i]);
					}
					else
					{
						dataRow2["standPrice"] = decimal.Parse(dataRow["StandPrice"].ToString());
						dataRow2["total"] = int.Parse(array2[i]) * decimal.Parse(dataRow["StandPrice"].ToString());
					}
				}
			}
			dataTable.Rows.Add(dataRow2);
		}
		return dataTable;
	}
	private void loadinfo()
	{
		DataSet dataSet = new DataSet();
		dataSet.Tables.Add(this.setNewDataTable());
		this.GridView1.DataSource = dataSet;
		this.GridView1.DataBind();
	}
}
